package day05;
import java.util.Scanner;
public class ClassTest {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
/*
        System.out.println("请输入年份");

        int year = scan.nextInt();
        System.out.println("请输入月份");
        int month = scan.nextInt();
        System.out.println("请输入日份");
        int day = scan.nextInt();
        int num = 0;
        for (int i = 1; i < month; i++) {

            switch (i) {
                case 1:
                case 3:
                case 5:
                case 7:
                case 8:
                case 10:
                case 12:
                    num += 31;
                    break;
                case 4:
                case 6:
                case 9:
                case 11:
                    num += 30;
                    break;
                case 2:
                    if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                        num += 28;
                    } else {
                        num += 29;
                    }

            }
        }
        int sum=num+day;
        System.out.println("今天是该年的第"+sum+"天");

 */
       test(555,2);


    }
    /*
     * 定义一个方法,传入年月,在控制台打印当月日历,已知1900.1.1日为星期一(扩展题)
     *
     * 1.求总天数
     * 2.求输入月份的上一个月最后一天是星期几:总天数%7,余数就是上个月最后一天的星期
     * */
    static void test(int year,int month){
        System.out.println("年:"+year+","+"月:"+month);
        int day=0;//总天数
        //1.求出相隔年数的总天数
        for(int i=1900;i<year;i++){
            if(i%400==0 || i%4==0 && i%100!=0){//判断是平年还是闰年
                day+=366;
            }else{
                day+=365;
            }
        }
        //2.求出相隔月份的总天数
        for(int i=1;i<month;i++){
            if(i==2){
                day+=year%400==0 || year%4==0 && year%100!=0 ? 29:28;
            }else if(i==4||i==6||i==9||i==11){
                day+=30;
            }else{
                day+=31;
            }
        }

        //2.求输入月份的上一个月最后一天是星期几
        int weeks=day%7;//上一个月最后一天的星期数

        //3.求当月的天数
        int thisDay=0;//当月天数
        switch (month){
            case 2:
                thisDay=year%400==0 || year%4==0 && year%100!=0 ? 29:28;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                thisDay=30;
                break;
            default:
                thisDay=31;
                break;
        }

        //4.打印日历
        System.out.print("一\t二\t三\t四\t五\t六\t日");
        System.out.println();

        //上一个月余几天,就打印几个空格
        for(int i=1;i<=weeks;i++){
            System.out.print("\t");
        }

        for(int i=1;i<=thisDay;i++){
            System.out.print(i+"\t");
            if((i+weeks)%7==0){//逢7换行
                System.out.println();
            }
        }
    }
}
